﻿package com.dwillonline.portfolio{
	import flash.display.*;
	import flash.net.*;
	import flash.events.*;

	public class Portfolio extends MovieClip {
		private var _navigation : Navigation;
		private var _preloader 	: MovieClip;
		private var _sections 	: Sprite = new Sprite();

		private var _xmlPath	: String = "siteXML.xml";
		private var _xmlLoader	: URLLoader;
		private var _xmlRequest	: URLRequest;

		private var _xml 		: XML;

		public function Portfolio():void {
			loadXML();
		}
		private function loadXML():void {
			_xmlRequest = new URLRequest(_xmlPath);
			_xmlLoader = new URLLoader(_xmlRequest);
			_xmlLoader.addEventListener(Event.COMPLETE, onXMLLoad);
		}
		private function onXMLLoad(e:Event):void {
			trace("XML LOADED");
			_xml = new XML(e.target.data);
			_navigation = new Navigation(_xml);

			loadSections();
		}
		private function loadSections():void {
			//addChild(_sections);

			for (var i:int = 0; i < _xml.section.length(); i++) {
				var sp:String = _xml.section[i].@path;

				var ur:URLRequest = new URLRequest(sp);
				var ul:Loader = new Loader();
				ul.load(ur);

				ul.contentLoaderInfo.addEventListener(Event.COMPLETE, onSectionLoad);

				trace(_xml.section[i].@name);
			}
		}
		private function onSectionLoad(e:Event):void {
			//addChild(e.target.);
			_sections.addChild(e.target.content);
			addChild(_sections);

		}
	}
}